package algotithm.interview.shoppee.test3II;

import java.io.*;

/**
 * @author zhouyanxiang
 * @Date 2021-03-2021/3/17-16:08
 */
public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        String str = reader.readLine().replaceAll("\\[","");
        str = str.replaceAll("\\]","");
        String[] arr = str.split("\\,");
        double m = arr.length;
        int n = (int) Math.sqrt(m);
        int[][] grid = new int[n][n];
        for (int j = 0; j < n; j++) {
            for (int i = 0 + j * n; i < (j+1)*n; i++) {
                grid[i / n][i % n] = Integer.parseInt(arr[i]);
            }
        }
        int res = minPathSum(grid);
        writer.write(res + "\n");
        writer.flush();
        writer.close();
        reader.close();
    }


    public static int minPathSum(int[][] grid) {
        int n = grid.length;
        int m = grid[0].length;
        for (int i = 1; i < n; i++) {
            grid[i][0] += grid[i-1][0];
        }
        for (int j = 1; j < m; j++) {
            grid[0][j] += grid[0][j-1];
        }
        for (int i = 1; i < n; i++) {
            for (int j = 1; j < m; j++) {
                grid[i][j] += Math.min(grid[i-1][j],grid[i][j-1]);
            }
        }
        return grid[n-1][m-1];
    }
}
